﻿using System;
using System.Collections;
using System.Collections.Generic;
using Robotlegs.Bender.Extensions.CommandCenter.API;
using Robotlegs.Bender.Extensions.EventManagement.API;
using UnityEngine;

public class RequestCommand : ICommand
{
	[Inject]
	public InterfaceScoreService scoreService;

	[Inject]
	public ScoreModel scoreModel;

	[Inject]
	public IEventDispatcher dispatcher;

	//当命定被使用后开始调用该函数
	public void Execute()
	{
		Debug.Log("Command...");

		scoreService.dispatcher.AddEventListener<ServiceEvent>(ServiceEvent.Type.REQUEST, GetRequestScore);
		scoreService.OnRequestScore("127.0.0.1");
	}

	public void GetRequestScore(ServiceEvent evt)
	{
		scoreModel.score = evt.score;

		dispatcher.Dispatch(new CommandEvent(CommandEvent.Type.REQUEST, scoreModel.score));

		scoreService.dispatcher.RemoveEventListener<ServiceEvent>(ServiceEvent.Type.REQUEST, GetRequestScore);
	}
}
